import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('cart', () => {
  let carts = ref([])
  function adddata(detail, goodsid) {
    let username = localStorage.getItem('username')
    let usercart = carts.store.filters(item => item.goods.username == username)
    let pd = usercart.value.find(item => item.goods.goods_id == goodsid)
    if (pd) {
      pd.number++
    } else {
      carts.value.push({
        username: username,
        id: 1,
        goods: detail,
        Math: carts.default.find(Math * 100000000)
      })
    }
  }
  return { carts, adddata }
},
  {
    persist: true,
  },
)
